﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace dure.math.geometry
{
    public class Vector3
    {
        public double X;
        public double Y;
        public double Z;

        public Vector3()
        {
            X = 0;
            Y = 0;
            Z = 0;
        }

        public Vector3(double x, double y, double z)
        {
            X = x;
            Y = y;
            Z = z;
        }

        public override bool Equals(object obj)
        {
            bool retVal = false;
            if (null != obj)
            {
                Vector3 vec = obj as Vector3;
                if (null != vec)
                {
                    retVal = (X == vec.X && Y == vec.Y && Z == vec.Z);
                }
            }
            return retVal;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override string ToString()
        {
            return "dure.math.geometry.Vector3D, X: " + X.ToString() + " Y: " + Y.ToString() + " Z: " + Z.ToString();
        }

        public static bool operator == (Vector3 lhs, Vector3 rhs)
        {
            return lhs.Equals(rhs);
        }
        public static bool operator != (Vector3 lhs, Vector3 rhs)
        {
            return !(lhs.Equals(rhs));
        }

        public static Vector3 operator +(Vector3 lhs, Vector3 rhs)
        {
            return new Vector3(lhs.X + rhs.X, lhs.Y + rhs.Y, lhs.Z + rhs.Z);
        }
        //public static Vector3 operator + (Vector3 other)
        //{
        //    return new Vector3(X + other.X, Y + other.Y, Z + other.Z);
        //}

        public static Vector3 operator -(Vector3 lhs, Vector3 rhs)
        {
            return new Vector3(lhs.X - rhs.X, lhs.Y - rhs.Y, lhs.Z - rhs.Z);
        }
        //public static Vector3 operator -(Vector3 other)
        //{
        //    return new Vector3(X - other.X, Y - other.Y, Z - other.Z);
        //}

        public static Vector3 operator *(Vector3 lhs, Vector3 rhs)
        {
            return new Vector3(lhs.X * rhs.X, lhs.Y * rhs.Y, lhs.Z * rhs.Z);
        }
        public static Vector3 operator /(Vector3 lhs, Vector3 rhs)
        {
            return new Vector3(lhs.X / rhs.X, lhs.Y / rhs.Y, lhs.Z / rhs.Z);
        }

        public static double Distance(Vector3 lhs, Vector3 rhs)
        {
            return Math.Sqrt(Math.Pow((lhs.X - rhs.X), 2.0) + Math.Pow((lhs.Y - rhs.Y), 2.0) + Math.Pow((lhs.Z - rhs.Z), 2.0));
        }

        public double Distance(Vector3 other)
        {
            return Distance(this, other);
        }

        public void Normalize()
        {
            if (X != 0 && Y != 0 && Z != 0)
            {
                var distance = Distance(this, new Vector3(0, 0, 0));
            }
        }
    }
}
